package service.impl;

import mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pojo.entity.SysUser;
import service.SysUserService;
import spring.entity.User;

import java.util.List;

/**
 * @author 吴阳基
 * @datetime 2024/1/15 20:39
 */
@Transactional
@Scope("prototype")//多例，每次请求都会创建一个新的对象，默认单例，每次请求都是同一个对象。
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {
    @Autowired//Resource
    private SysUserMapper sysUserMapper;

    @Override
    public List<SysUser> getList(SysUser sysUser) {
        try {
            return sysUserMapper.selectSysUserList(sysUser);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int add(SysUser sysUser) {
        int result = 0;
        try {
            if (sysUserMapper.add(sysUser) == 1) {
                result = 1;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public SysUser login(String account, String password) {
        return null;
    }

    @Override
    public int getUserCount(String queryRealName, Integer queryRoleId) {
        return sysUserMapper.getUserCount(queryRealName,queryRoleId);
    }

    @Override
    public List<SysUser> getUserList(String queryRealName, Integer queryRoleId, Integer pageIndex, int pageSize) {
        return sysUserMapper.getUserList(queryRealName,queryRoleId,pageIndex,pageSize);
    }

    @Override
    public SysUser getUserById(Integer id) {
        return sysUserMapper.getUserById(id);
    }

    @Override
    public int update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    public SysUserMapper getSysUserMapper() {
        return sysUserMapper;
    }

    public void setSysUserMapper(SysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }
}
